﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="DicasViagens.HomePage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DicasViagens"
    xmlns:data="using:DicasViagens.Data"
    xmlns:tiles="using:DicasViagens.VariableTemplate"
    xmlns:common="using:DicasViagens.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>

        

        <DataTemplate x:Key="SnappedItemTemplate">
            <Grid Margin="6"  Width="280">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Border  Width="60" Height="60">
                    <Image Source="{Binding ImageUrl}" Stretch="UniformToFill"/>
                </Border>
                <StackPanel Grid.Column="1" Margin="10,0,0,0">
                    <TextBlock Text="{Binding Nome}" Style="{StaticResource ItemTextStyle}" MaxHeight="40"/>
                    <TextBlock Text="{Binding SubTitulo}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap"/>
                </StackPanel>
            </Grid>
        </DataTemplate>

        <!--
            Collection of grouped items displayed by this page, bound to a subset
            of the complete item list because items in groups cannot be virtualized
        -->
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Groups}"
            IsSourceGrouped="true"
            ItemsPath="Items"
            d:Source="{Binding AllGroups, Source={d:DesignInstance Type=data:HubPageDataSource, IsDesignTimeCreatable=True}}"/>

        <tiles:VariableTiles x:Key="MyTemplates"
                             NormalTemplate="{StaticResource NormalTemplate}"
                             VerticalTemplate="{StaticResource VerticalTemplate}">
        </tiles:VariableTiles>

        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">App Slogan goes Here</x:String>
    </Page.Resources>

    <common:LayoutAwarePage.TopAppBar>
        <AppBar Height="110" Background="#FF3238AA">
            <StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
                <Button Content="Home" Height="92" Margin="5,0"  Style="{StaticResource AppBarHomeBtnStyle}" Width="92"/>
            </StackPanel>
        </AppBar>
    </common:LayoutAwarePage.TopAppBar>
    

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <!-- Horizontal scrolling grid used in most view states -->
        <ScrollViewer x:Name="scrollViewer" Grid.RowSpan="2" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" 
                      ZoomMode="Disabled" VerticalScrollMode="Disabled">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="140"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>


                <Image x:Name="imgEmpresa" Stretch="Fill" Source="Assets/Images/HubPageBanner.png" Margin="0" Grid.RowSpan="2"/>


                <tiles:VariableTileControl
    				x:Name="itemGridView"
    				AutomationProperties.AutomationId="itemGridView"
    				AutomationProperties.Name="Grouped Items"
    				Padding="100,10,40,46"
    				ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
    				ItemTemplateSelector ="{StaticResource MyTemplates}"
    				SelectionMode="None"
                     IsItemClickEnabled="True"
                    ItemClick="itemGridView_Tapped_1"
                    
    				IsSwipeEnabled="false" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Column="1" Grid.Row="1" Width="Auto">

                    <tiles:VariableTileControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </tiles:VariableTileControl.ItemsPanel>
                    <tiles:VariableTileControl.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <Grid Margin="1,0,0,6">
                                        <Button
                                            Click="Header_Click"
    										AutomationProperties.Name="Group Title"
    										Style="{StaticResource TextPrimaryButtonStyle}">
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock FontWeight="Light" Text="{Binding Nome}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                                <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
                                            </StackPanel>
                                        </Button>
                                    </Grid>
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <VariableSizedWrapGrid ItemHeight="10" ItemWidth="10" Orientation="Vertical" Margin="0,0,80,0"/>
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </tiles:VariableTileControl.GroupStyle>
                </tiles:VariableTileControl>
                <Grid Height="140" VerticalAlignment="Bottom" Grid.Row="1" Margin="0,0,0,94" Background="#CC000000">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="120"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto " />
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock x:Name="txtNome" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Nome" VerticalAlignment="Center" FontSize="29.333" FontFamily="Segoe UI" FontWeight="Light" Margin="0,2" Grid.Column="1"/>
                    <TextBlock x:Name="txtSobre" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Sobre" VerticalAlignment="Center" FontSize="14.667" FontFamily="Segoe UI" FontWeight="Light" Grid.Column="1" Grid.Row="1" Width="Auto" Margin="0,0,0,5"/>
                    
                </Grid>

            </Grid>

        </ScrollViewer>

        <!-- Vertical scrolling list only used when snapped -->
        <ListView
    		x:Name="itemListView"
    		AutomationProperties.AutomationId="ItemListView"
    		AutomationProperties.Name="Grouped Items"
    		Margin="0,130,0,0"
    		Padding="10,0,0,60"
    		ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
    		ItemTemplate="{StaticResource SnappedItemTemplate}"
    		SelectionMode="None"
            IsItemClickEnabled="True"
            ItemClick="itemGridView_Tapped_1"
    		IsSwipeEnabled="false" Grid.ColumnSpan="2" Grid.RowSpan="2" Visibility="Collapsed">

            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="7,7,0,0">
                                <Button
                                    Click="Header_Click"
    								AutomationProperties.Name="Group Title"
    								Style="{StaticResource TextPrimaryButtonStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Nome}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                        <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>

        <!-- Back button and page title -->
        <Grid Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Grid.Column="1" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}" FontSize="48"/>
            <Image x:Name="image" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Column="1" Stretch="None" Source="Assets/AppLogo.png" Margin="0,0,48,0"/>
        </Grid>


        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>-->

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,137,10,56"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="scrollViewer">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="image">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation Duration="0" Storyboard.TargetProperty="(TextBlock.FontSize)" Storyboard.TargetName="pageTitle" d:IsOptimized="True" To="37.333"/>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Thickness>0,0,5,37</Thickness>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="backButton">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Thickness>20,0,0,4</Thickness>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <x:Double>34</x:Double>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
